home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / GENERIC.H < prev    next >
C/C++ Source or Header  |  1992-12-08  |  8KB  |  265 lines

  1. /*
  2.  * generic.h -- generic include stuff for new PCCTS ANTLR.
  3.  *
  4.  * SOFTWARE RIGHTS
  5.  *
  6.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  7.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  8.  * company may do whatever they wish with source code distributed with
  9.  * PCCTS or the code generated by PCCTS, including the incorporation of
  10.  * PCCTS, or its output, into commerical software.
  11.  * 
  12.  * We encourage users to develop software with PCCTS.  However, we do ask
  13.  * that credit is given to us for developing PCCTS.  By "credit",
  14.  * we mean that if you incorporate our source code into one of your
  15.  * programs (commercial product, research project, or otherwise) that you
  16.  * acknowledge this fact somewhere in the documentation, research report,
  17.  * etc...  If you like PCCTS and have developed a nice tool with the
  18.  * output, please mention that you developed it using PCCTS.  In
  19.  * addition, we ask that this header remain intact in our source code.
  20.  * As long as these guidelines are kept, we expect to continue enhancing
  21.  * this system and expect to make other tools available as they are
  22.  * completed.
  23.  *
  24.  * ANTLR 1.06
  25.  * Terence Parr
  26.  * Purdue University
  27.  * 1989-1992
  28.  */
  29.  
  30. #define StrSame            0
  31.  
  32. /* User may redefine how line information looks */
  33. #define LineInfoFormatStr "# %d \"%s\"\n"
  34.  
  35. #define ZZLEXBUFSIZE 4000
  36.  
  37. /* Tree/FIRST/FOLLOW defines -- valid only after all grammar has been read */
  38. #define ALT            TokenNum+1
  39. #define SET            TokenNum+2
  40. #define TREE_REF    TokenNum+3
  41.  
  42.                     /* E r r o r  M a c r o s */
  43.  
  44. #ifdef MPW        /* Macintosh Programmer's Workshop */
  45. #define ErrHdr "File \"%s\"; Line %d #"
  46. #else
  47. #define ErrHdr "%s, line %d:"
  48. #endif
  49.  
  50. #define fatal(err)        fatalFL(err, __FILE__, __LINE__)
  51. #define warnNoFL(err)    fprintf(stderr, "warning: %s\n", err);
  52. #define warnFL(err,f,l)                                                            \
  53.             {fprintf(stderr, ErrHdr, f, l);                                        \
  54.             fprintf(stderr, " warning: %s\n", err);}
  55. #define warn(err)                                                                \
  56.             {fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);                \
  57.             fprintf(stderr, " warning: %s\n", err);}
  58. #define warnNoCR( err )                                                            \
  59.             {fprintf(stderr, ErrHdr, FileStr[CurFile], zzline);                \
  60.             fprintf(stderr, " warning: %s", err);}
  61. #define eMsg1(s,a)    eMsg3(s,a,NULL,NULL)
  62. #define eMsg2(s,a,b)    eMsg3(s,a,b,NULL)
  63.  
  64.                 /* S a n i t y  C h e c k i n g */
  65.  
  66. #ifndef require
  67. #define require(expr, err) {if ( !(expr) ) fatal(err);}
  68. #endif
  69.  
  70.                     /* L i s t  N o d e s */
  71.  
  72. typedef struct _l {
  73.             char *elem;            /* pointer to any kind of element */
  74.             struct _l *next;
  75.         } ListNode;
  76.  
  77. /* Define a Cycle node which is used to track lists of cycles for later
  78.  * reconciliation by ResolveFoCycles().
  79.  */
  80. typedef struct _c {
  81.             int croot;            /* cycle root */
  82.             set cyclicDep;        /* cyclic dependents */
  83.             unsigned deg;        /* degree of FOLLOW set of croot */
  84.         } Cycle;
  85.  
  86. typedef struct _e {
  87.             int tok;            /* error class name == TokenStr[tok] */
  88.             ListNode *elist;    /* linked list of elements in error set */
  89.             set eset;
  90.             int setdeg;            /* how big is the set */
  91.             int lexclass;        /* which lex class is it in? */
  92.         } ECnode;
  93.  
  94. #define newListNode    (ListNode *) calloc(1, sizeof(ListNode));
  95. #define newCycle    (Cycle *) calloc(1, sizeof(Cycle));
  96. #define newECnode    (ECnode *) calloc(1, sizeof(ECnode));
  97.  
  98.  
  99.                 /* H a s h  T a b l e  E n t r i e s */
  100.  
  101. typedef struct _t {                /* Token name or expression */
  102.             char *str;
  103.             struct _t *next;
  104.             int token;            /* token number */
  105.             int errclassname;    /* is it a errclass name or token */
  106.             char *action;
  107.         } TermEntry;
  108.  
  109. typedef struct _r {                /* Rule name and ptr to start of rule */
  110.             char *str;
  111.             struct _t *next;
  112. /*            int passedSomething;/* is this rule passed something? */
  113. /*            int returnsSomething;/* does this rule return something? */
  114.             int rulenum;        /* RulePtr[rulenum]== ptr to RuleBlk junction */
  115.             int noAST;            /* gen AST construction code? (def==gen code) */
  116.             char *egroup;        /* which error group (err reporting stuff) */
  117.         } RuleEntry;
  118.  
  119. typedef struct _f {                /* cache Fi/Fo set */
  120.             char *str;            /* key == (rulename, computation, k) */
  121.             struct _f *next;
  122.             set fset;            /* First/Follow of rule */
  123.             set rk;                /* set of k's remaining to be done after ruleref */
  124.             int incomplete;        /* only w/FOLLOW sets.  Use only if complete */
  125.         } CacheEntry;
  126.  
  127. #define newTermEntry(s)        (TermEntry *) newEntry(s, sizeof(TermEntry))
  128. #define newRuleEntry(s)        (RuleEntry *) newEntry(s, sizeof(RuleEntry))
  129. #define newCacheEntry(s)    (CacheEntry *) newEntry(s, sizeof(CacheEntry))
  130.  
  131.                     /* L e x i c a l  C l a s s */
  132.  
  133. /* to switch lex classes, switch ExprStr and Texpr (hash table) */
  134. typedef struct _lc {
  135.             char *class, **exprs;
  136.             Entry **htable;
  137.         } LClass;
  138.  
  139. typedef struct _exprOrder {
  140.             char *expr;
  141.             int lclass;
  142.         } Expr;
  143.  
  144.  
  145. typedef Graph Attrib;
  146.  
  147.                         /* M a x i m u m s */
  148.  
  149. #ifndef HashTableSize
  150. #define HashTableSize    253
  151. #endif
  152. #ifndef StrTableSize
  153. #define StrTableSize    15000    /* all tokens, nonterminals, rexprs stored here */
  154. #endif
  155. #define MaxLexClasses    50        /* how many automatons */
  156. #define TokenStart        2        /* MUST be in 1 + EofToken */
  157. #define EofToken        1        /* Always predefined to be 1 */
  158. #define MaxNumFiles        20
  159. #define MaxFileName        300        /* largest file name size */
  160. #define MaxRuleName        100        /* largest rule name size */
  161. #define TSChunk            100        /* how much to expand TokenStr/ExprStr each time */
  162. #define FoStackSize        100        /* deepest FOLLOW recursion possible */
  163.  
  164. /* AST token types */
  165. #define ASTexclude        0
  166. #define ASTchild        1
  167. #define ASTroot            2
  168. #define ASTinclude        3        /* include subtree made by rule ref */
  169.  
  170.                            /* V a r i a b l e s */
  171.  
  172. extern int tp;
  173. extern Junction *SynDiag;
  174. extern char Version[];
  175. extern void (*fpPrint[])();
  176. extern set (*fpReach[])();
  177. extern Tree *(*fpTraverse[])();
  178. extern void (**fpTrans)();
  179. extern void (**fpJTrans)();
  180. extern void (*C_Trans[])();
  181. extern void (*C_JTrans[])();
  182. extern int BlkLevel;
  183. extern int CurFile;
  184. extern char *CurRule;
  185. extern RuleEntry *CurRuleNode;
  186. extern char *FileStr[];
  187. extern int NumFiles;
  188. extern int EpToken;
  189. extern Entry    **Tname,
  190.                 **Texpr,
  191.                 **Rname,
  192.                 **Fcache,
  193.                 **Tcache;
  194. extern ListNode *ExprOrder;
  195. extern ListNode **Cycles;
  196. extern int TokenNum;
  197. extern ListNode *BeforeActions, *AfterActions, *LexActions;
  198. extern ListNode *eclasses;
  199. extern char    *HdrAction;
  200. extern FILE    *ErrFile;
  201. extern char *ErrFileName;
  202. extern char *DlgFileName;
  203. extern char *DefFileName;
  204. extern int NumRules;
  205. extern Junction **RulePtr;
  206. extern int LL_k;
  207. extern char *decodeJType[];
  208. extern int PrintOut;
  209. extern int PrintAnnotate;
  210. extern int CodeGen;
  211. extern int LexGen;
  212. extern int setnum;
  213. extern int wordnum;
  214. extern int GenAST;
  215. extern int GenANSI;
  216. extern int **FoStack;
  217. extern int **FoTOS;
  218. extern int GenExprSets;
  219. extern FILE *DefFile;
  220. extern int CannotContinue;
  221. extern int GenCR;
  222. extern int GenLineInfo;
  223. extern int action_file, action_line;
  224. extern int TraceGen;
  225. extern int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
  226. extern char *CurAmbigbtype;
  227. extern int elevel;
  228. extern int GenEClasseForRules;
  229. extern FILE *input, *output;
  230. extern char **TokenStr, **ExprStr;
  231. extern int CurrentLexClass, NumLexClasses;
  232. extern LClass lclass[];
  233. extern char LexStartSymbol[];
  234. extern char    *CurRetDef;
  235. extern char    *CurParmDef;
  236. extern int OutputLL_k;
  237. extern int TreeResourceLimit;
  238. extern int DemandLookahead;
  239. extern char *RulePrefix;
  240. extern int GenStdPccts;
  241. extern char *stdpccts;
  242. extern int ParseWithPredicates;
  243. extern int ConstrainSearch;
  244.  
  245. #ifdef MEMCHK
  246. #include "trax.h"
  247. #else
  248. #ifdef __STDC__
  249. void *malloc(unsigned int), *calloc(unsigned int, unsigned int);
  250. void *realloc(void *, unsigned int);
  251. void free(void *);  /* TJP added for ANSI compilation */
  252. #else
  253. char *malloc(), *calloc(), *realloc();
  254. #endif
  255. #endif
  256.  
  257. #ifndef TRUE
  258. #define TRUE 1
  259. #endif
  260. #ifndef FALSE
  261. #define FALSE 0
  262. #endif
  263.  
  264. #include "proto.h"
  265.